package org.jeecgframework.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.web.service.UploadHallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**   
 * @Title: UploadHallService
 * @Description: 上传影厅信息
 * @author ZhangYunlong
 * @date 2016-04-01
 * @version V1.0   
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/uploadHallController")
public class UploadHallController extends BaseController {

	@Autowired
	private UploadHallService uploadHallService;
	/**
	 * 设备以及备件信息列表 页面跳转
	 * @return
	 */
	@RequestMapping(params = "uploadFile")
	public ModelAndView uploadFile(HttpServletRequest request) {
		return new ModelAndView("com/zybk/file_upload/uploadRoom");
	}
	
	/**
	 * @Description 解析EXCEL
	 * @param req
	 */
	@ResponseBody
	@RequestMapping(params = "importExcel")
	public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
		AjaxJson j = new AjaxJson();
		try {
			uploadHallService.parseExcel(request,j);
		} catch (Exception e) {
			j.setMsg("导入失败");
			j.setSuccess(false);
			e.printStackTrace();
		}
		j.setMsg("导入成功");
		return j;
	}
	
	@ResponseBody
	@RequestMapping(params="readExcel")
	public void readExcel(HttpServletRequest request,
			@RequestParam(value="filePath",defaultValue="")String filePath){
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>进入解析影厅EXCEL action");
		long begin = System.currentTimeMillis();
		ThreadLocal<HttpServletRequest> req = new ThreadLocal<HttpServletRequest>();
		req.set(request);
		uploadHallService.readExcel(filePath);
		long end = System.currentTimeMillis();
		System.out.println("解析EXCEL影厅数据并保存数据  用时："+(end - begin) / 1000 +"." + (end - begin) % 1000 +"秒");
	}
	
	
}
